<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/10/25
  Time: 10:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>礼物管理 - 豆鲨后台管理系统</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <meta name="keywords" content="礼物管理 - 豆鲨后台管理系统">
    <meta name="description" content="礼物管理 - 豆鲨后台管理系统">
    <meta name="author" content="yinqi">
    <link href="${pageContext.request.contextPath}/doushahoutai/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/doushahoutai/css/materialdesignicons.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/doushahoutai/css/style.min.css" rel="stylesheet">

</head>

<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <aside class="lyear-layout-sidebar">

            <!-- logo -->
            <div id="logo" class="sidebar-header">
            </div>
            <div class="lyear-layout-sidebar-scroll">

                <nav class="sidebar-main">
                    <ul class="nav nav-drawer">
                        <%--<li class="nav-item active"> <a href="index.html"><i class="mdi mdi-home"></i> 后台首页</a> </li>--%>
                        <li class="nav-item nav-item-has-subnav">
                            <a href="javascript:void(0)"><i class="mdi mdi-account"></i>用户管理</a>
                            <ul class="nav nav-subnav">
                                <li> <a href="${pageContext.request.contextPath}/front/showUser.jsp">所有用户</a> </li>
                                <li> <a href="${pageContext.request.contextPath}/front/showUser.jsp">用户新增</a> </li>
                            </ul>
                        </li>
                        <li class="nav-item nav-item-has-subnav">
                            <a href="javascript:void(0)"><i class="mdi mdi-file-video"></i> 直播管理</a>
                            <ul class="nav nav-subnav">
                                <li> <a href="${pageContext.request.contextPath}/LiveController/BackLive">直播间管理</a> </li>
                            </ul>
                        </li>
                        <li class="nav-item nav-item-has-subnav">
                            <a href="javascript:void(0)"><i class="mdi mdi-filmstrip"></i> 视频管理</a>
                            <ul class="nav nav-subnav">
                                <li> <a href="${pageContext.request.contextPath}/video/skipVideoManage">所有视频</a> </li>
                            </ul>
                        </li>
                        <li class="nav-item nav-item-has-subnav">
                            <a href="javascript:void(0)"><i class="mdi mdi-folder-open"></i>分类管理</a>
                            <ul class="nav nav-subnav">
                                <li> <a href="${pageContext.request.contextPath}/LiveController/BackType">分类管理</a> </li>
                            </ul>
                        </li>
                        <li class="nav-item nav-item-has-subnav">
                            <a href="javascript:void(0)"><i class="mdi mdi-cart-outline"></i>礼物管理</a>
                            <ul class="nav nav-subnav"  style="display: block;">
                                <li class="active"> <a href="${pageContext.request.contextPath}/LiveController/BackGift">礼物管理</a> </li>
                                <li> <a href="${pageContext.request.contextPath}/LiveController/BackGiftRecord">礼物记录管理</a> </li>
                            </ul>
                        </li>
                        
                    </ul>
                </nav>

                <div class="sidebar-footer">
                    <p class="copyright">Copyright &copy; 2019. All rights reserved. More Templates：豆鲨</p>
                </div>
            </div>

        </aside>
        <!--End 左侧导航-->

        <!--头部信息-->
        <header class="lyear-layout-header">

            <nav class="navbar navbar-default">
                <div class="topbar">

                    <div class="topbar-left">
                        <div class="lyear-aside-toggler">
                            <span class="lyear-toggler-bar"></span>
                            <span class="lyear-toggler-bar"></span>
                            <span class="lyear-toggler-bar"></span>
                        </div>
                        <span class="navbar-page-title"> 礼物管理 </span>
                    </div>

                    <ul class="topbar-right"  id="login1">
                        <li class="dropdown dropdown-profile">
                            <a href="javascript:void(0)" data-toggle="dropdown">
                                <img class="img-avatar img-avatar-48 m-r-10" src="${pageContext.request.contextPath}/doushahoutai/images/users/avatar.jpg" alt="笔下光年" />
                                <span>笔下光年 <span class="caret"></span></span>
                            </a>
                            <ul class="dropdown-menu dropdown-menu-right">
                                <li> <a href="lyear_pages_profile.html"><i class="mdi mdi-account"></i> 个人信息</a> </li>
                                <li> <a href="lyear_pages_edit_pwd.html"><i class="mdi mdi-lock-outline"></i> 修改密码</a> </li>
                                <li> <a href="javascript:void(0)"><i class="mdi mdi-delete"></i> 清空缓存</a></li>
                                <li class="divider"></li>
                                <li> <a href="lyear_pages_login.html"><i class="mdi mdi-logout-variant"></i> 退出登录</a> </li>
                            </ul>
                        </li>
                        <!--切换主题配色-->
                        <li class="dropdown dropdown-skin">
                            <span data-toggle="dropdown" class="icon-palette"><i class="mdi mdi-palette"></i></span>
                            <ul class="dropdown-menu dropdown-menu-right" data-stopPropagation="true">
                                <li class="drop-title"><p>主题</p></li>
                                <li class="drop-skin-li clearfix">
                  <span class="inverse">
                    <input type="radio" name="site_theme" value="default" id="site_theme_1" checked>
                    <label for="site_theme_1"></label>
                  </span>
                                    <span>
                    <input type="radio" name="site_theme" value="dark" id="site_theme_2">
                    <label for="site_theme_2"></label>
                  </span>
                                    <span>
                    <input type="radio" name="site_theme" value="translucent" id="site_theme_3">
                    <label for="site_theme_3"></label>
                  </span>
                                </li>
                                <li class="drop-title"><p>LOGO</p></li>
                                <li class="drop-skin-li clearfix">
                  <span class="inverse">
                    <input type="radio" name="logo_bg" value="default" id="logo_bg_1" checked>
                    <label for="logo_bg_1"></label>
                  </span>
                                    <span>
                    <input type="radio" name="logo_bg" value="color_2" id="logo_bg_2">
                    <label for="logo_bg_2"></label>
                  </span>
                                    <span>
                    <input type="radio" name="logo_bg" value="color_3" id="logo_bg_3">
                    <label for="logo_bg_3"></label>
                  </span>
                                    <span>
                    <input type="radio" name="logo_bg" value="color_4" id="logo_bg_4">
                    <label for="logo_bg_4"></label>
                  </span>
                                    <span>
                    <input type="radio" name="logo_bg" value="color_5" id="logo_bg_5">
                    <label for="logo_bg_5"></label>
                  </span>
                                    <span>
                    <input type="radio" name="logo_bg" value="color_6" id="logo_bg_6">
                    <label for="logo_bg_6"></label>
                  </span>
                                    <span>
                    <input type="radio" name="logo_bg" value="color_7" id="logo_bg_7">
                    <label for="logo_bg_7"></label>
                  </span>
                                    <span>
                    <input type="radio" name="logo_bg" value="color_8" id="logo_bg_8">
                    <label for="logo_bg_8"></label>
                  </span>
                                </li>
                                <li class="drop-title"><p>头部</p></li>
                                <li class="drop-skin-li clearfix">
                  <span class="inverse">
                    <input type="radio" name="header_bg" value="default" id="header_bg_1" checked>
                    <label for="header_bg_1"></label>                      
                  </span>
                                    <span>                                                     
                    <input type="radio" name="header_bg" value="color_2" id="header_bg_2">
                    <label for="header_bg_2"></label>                      
                  </span>
                                    <span>                                                     
                    <input type="radio" name="header_bg" value="color_3" id="header_bg_3">
                    <label for="header_bg_3"></label>
                  </span>
                                    <span>
                    <input type="radio" name="header_bg" value="color_4" id="header_bg_4">
                    <label for="header_bg_4"></label>                      
                  </span>
                                    <span>                                                     
                    <input type="radio" name="header_bg" value="color_5" id="header_bg_5">
                    <label for="header_bg_5"></label>                      
                  </span>
                                    <span>                                                     
                    <input type="radio" name="header_bg" value="color_6" id="header_bg_6">
                    <label for="header_bg_6"></label>                      
                  </span>
                                    <span>                                                     
                    <input type="radio" name="header_bg" value="color_7" id="header_bg_7">
                    <label for="header_bg_7"></label>
                  </span>
                                    <span>
                    <input type="radio" name="header_bg" value="color_8" id="header_bg_8">
                    <label for="header_bg_8"></label>
                  </span>
                                </li>
                                <li class="drop-title"><p>侧边栏</p></li>
                                <li class="drop-skin-li clearfix">
                  <span class="inverse">
                    <input type="radio" name="sidebar_bg" value="default" id="sidebar_bg_1" checked>
                    <label for="sidebar_bg_1"></label>
                  </span>
                                    <span>
                    <input type="radio" name="sidebar_bg" value="color_2" id="sidebar_bg_2">
                    <label for="sidebar_bg_2"></label>
                  </span>
                                    <span>
                    <input type="radio" name="sidebar_bg" value="color_3" id="sidebar_bg_3">
                    <label for="sidebar_bg_3"></label>
                  </span>
                                    <span>
                    <input type="radio" name="sidebar_bg" value="color_4" id="sidebar_bg_4">
                    <label for="sidebar_bg_4"></label>
                  </span>
                                    <span>
                    <input type="radio" name="sidebar_bg" value="color_5" id="sidebar_bg_5">
                    <label for="sidebar_bg_5"></label>
                  </span>
                                    <span>
                    <input type="radio" name="sidebar_bg" value="color_6" id="sidebar_bg_6">
                    <label for="sidebar_bg_6"></label>
                  </span>
                                    <span>
                    <input type="radio" name="sidebar_bg" value="color_7" id="sidebar_bg_7">
                    <label for="sidebar_bg_7"></label>
                  </span>
                                    <span>
                    <input type="radio" name="sidebar_bg" value="color_8" id="sidebar_bg_8">
                    <label for="sidebar_bg_8"></label>
                  </span>
                                </li>
                            </ul>
                        </li>
                        <!--切换主题配色-->
                    </ul>

                </div>
            </nav>

        </header>
        <!--End 头部信息-->

        <!--页面主要内容-->
        <main class="lyear-layout-content">

            <div class="container-fluid">

                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-toolbar clearfix">
                                <form class="pull-right search-bar" method="get" action="#!" role="form">
                                    <div class="input-group">
                                        <div class="input-group-btn">
                                            <input type="hidden" name="search_field" id="search-field" value="title">
                                            <button class="btn btn-default dropdown-toggle" id="search-btn" data-toggle="dropdown" type="button" aria-haspopup="true" aria-expanded="false">礼物名</button>
                                            <%--<ul class="dropdown-menu">
                                                <li> <a tabindex="-1" href="javascript:void(0)" data-field="title">礼物名</a> </li>
                                                <li> <a tabindex="-1" href="javascript:void(0)" data-field="cat_name">主播</a> </li>
                                            </ul>--%>
                                        </div>
                                        <input type="text" class="form-control" value="" id="keyword" name="keyword" placeholder="请输入名称">
                                    </div>
                                </form>
                                <div class="toolbar-btn-action">
                                    <a class="btn btn-primary m-r-5" href="#!" data-toggle="modal" data-target="#myModal"><i class="mdi mdi-plus"></i> 新增</a>
                                    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="display: none;">
                                        <div class="modal-dialog" role="document">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                                                    <h4 class="modal-title" id="myModalLabel">新增礼物</h4>
                                                </div>
                                                <div class="modal-body">
                                                    <form action="" method="post" class="row" id="formAdd">
                                                        <div class="form-group col-md-12">
                                                            <label for="giftName">礼物名</label>
                                                            <input type="text" class="form-control" id="giftName" name="giftName" value="" placeholder="请输入标题">
                                                            <input type="hidden" id="giftId">
                                                        </div>
                                                        <div class="form-group col-md-12">
                                                            <label for="giftPrice">礼物价格</label>
                                                            <div class="clearfix">
                                                                <input type="text" class="form-control" id="giftPrice" name="giftPrice" value="" placeholder="请输入价格">
                                                            </div>
                                                        </div>
                                                        <div class="form-group col-md-12">
                                                            <label>礼物图片上传</label>
                                                            <div class="form-controls">
                                                                <ul class="list-inline clearfix lyear-uploads-pic">
                                                                    <li class="col-xs-4 col-sm-3 col-md-2">
                                                                        <input type="file" name="upload" id="upload" style="display: none;" />
                                                                        <a class="pic-add" id="add-pic-btn" href="#!" title="点击上传"></a>
                                                                    </li>
                                                                </ul>
                                                            </div>
                                                        </div>
                                                        <div class="form-group col-md-12">
                                                            <label>礼物动态图上传</label>
                                                            <div class="form-controls">
                                                                <ul class="list-inline clearfix lyear-uploads-pic">
                                                                    <li class="col-xs-4 col-sm-3 col-md-2">
                                                                        <input type="file" name="upload" id="uploadGif" style="display: none;" />
                                                                        <a class="pic-add" id="add-pic-btnGif" href="#!" title="点击上传"></a>
                                                                    </li>
                                                                </ul>
                                                            </div>
                                                        </div>
                                                        
                                                    </form>
                                                </div>
                                                    <div class="modal-footer">
                                                        <button type="button" class="btn btn-default colse" data-dismiss="modal">关闭</button>
                                                        <button type="button" class="btn btn-primary" id="add">点击新增</button>
                                                    </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="modal fade" id="updataModal" tabindex="-1" role="dialog" aria-labelledby="updataModalLabel" style="display: none;">
                                            <div class="modal-dialog" role="document">
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                                                        <h4 class="modal-title" id="updataModalLabel">修改礼物</h4>
                                                    </div>
                                                    <div class="modal-body">
                                                        <form action="" method="post" class="row" id="formAdd1">
                                                            <div class="form-group col-md-12">
                                                                <label for="giftName">礼物名</label>
                                                                <input type="text" class="form-control" id="giftName1" name="giftName" value="" placeholder="请输入标题">
                                                            </div>
                                                            <div class="form-group col-md-12">
                                                                <label for="giftPrice">礼物价格</label>
                                                                <div class="clearfix">
                                                                    <input type="text" class="form-control" id="giftPrice1" name="giftPrice" value="" placeholder="请输入价格">
                                                                </div>
                                                            </div>
                                                            <div class="form-group col-md-12">
                                                                <label>礼物图片上传</label>
                                                                <div class="form-controls">
                                                                    <ul class="list-inline clearfix lyear-uploads-pic">
                                                                        <li class="col-xs-4 col-sm-3 col-md-2">
                                                                            <input type="file" name="upload" id="upload1" style="display: none;" />
                                                                            <a class="pic-add" id="add-pic-btn1" href="#!" title="点击上传"></a>
                                                                        </li>
                                                                    </ul>
                                                                </div>
                                                            </div>
                                                            <div class="form-group col-md-12">
                                                                <label>礼物动态图上传</label>
                                                                <div class="form-controls">
                                                                    <ul class="list-inline clearfix lyear-uploads-pic">
                                                                        <li class="col-xs-4 col-sm-3 col-md-2">
                                                                            <input type="file" name="upload" id="uploadGif1" style="display: none;" />
                                                                            <a class="pic-add" id="add-pic-btnGif1" href="#!" title="点击上传"></a>
                                                                        </li>
                                                                    </ul>
                                                                </div>
                                                            </div>

                                                        </form>
                                                    </div>
                                                    <div class="modal-footer">
                                                        <button type="button" class="btn btn-default colse" data-dismiss="modal">关闭</button>
                                                        <button type="button" class="btn btn-primary" id="updata">点击修改</button>
                                                    </div>
                                                </div>
                                            </div>
                                        
                                    <%--<a class="btn btn-success m-r-5" href="#!"><i class="mdi mdi-check"></i> 启用</a>
                                    <a class="btn btn-warning m-r-5" href="#!"><i class="mdi mdi-block-helper"></i> 禁用</a>
                                    <a class="btn btn-danger" href="#!"><i class="mdi mdi-window-close"></i> 删除</a>--%>
                                </div>
                            </div>
                            <div class="card-body">

                                <div class="table-responsive">
                                    <table class="table table-bordered">
                                        <thead>
                                        <tr>
                                            <%--<th>
                                                <label class="lyear-checkbox checkbox-primary">
                                                    <input type="checkbox" id="check-all"><span></span>
                                                </label>
                                            </th>--%>
                                            <th>编号</th>
                                            <th>礼物名</th>
                                            <th>礼物图片</th>
                                            <th>礼物动态图</th>
                                            <th>礼物价格</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody id="tbodyOne">
                                        <%--<tr>
                                            <td>
                                                <label class="lyear-checkbox checkbox-primary">
                                                    <input type="checkbox" name="ids[]" value="1"><span></span>
                                                </label>
                                            </td>
                                            <td>1</td>
                                            <td>第01章 天涯思君不可忘</td>
                                            <td>《倚天屠龙记》</td>
                                            <td>金庸</td>
                                            <td>36</td>
                                            <td><font class="text-success">正常</font></td>
                                            <td>
                                                <div class="btn-group">
                                                    <a class="btn btn-xs btn-default" href="#!" title="编辑" data-toggle="tooltip"><i class="mdi mdi-pencil"></i></a>
                                                    <a class="btn btn-xs btn-default" href="#!" title="删除" data-toggle="tooltip"><i class="mdi mdi-window-close"></i></a>
                                                </div>
                                            </td>
                                        </tr>--%>
                                        
                                        </tbody>
                                    </table>
                                </div>
                                <ul class="pagination">
                                    <%--<li class="disabled"><span>«</span></li>
                                    <li class="active"><span>1</span></li>
                                    <li><a href="#1">2</a></li>
                                    <li><a href="#1">3</a></li>
                                    <li><a href="#1">4</a></li>
                                    <li><a href="#1">5</a></li>
                                    <li><a href="#1">6</a></li>
                                    <li><a href="#1">7</a></li>
                                    <li><a href="#1">8</a></li>
                                    <li class="disabled"><span>...</span></li>
                                    <li><a href="#!">14452</a></li>
                                    <li><a href="#!">14453</a></li>
                                    <li><a href="#!">»</a></li>--%>
                                </ul>

                            </div>
                        </div>
                    </div>

                </div>

            </div>

        </main>
        <!--End 页面主要内容-->
    </div>
</div>

<script type="text/javascript" src="${pageContext.request.contextPath}/doushahoutai/js/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/doushahoutai/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/doushahoutai/js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/doushahoutai/js/main.min.js"></script>
<script type="text/javascript">
    $(function(){
        $('.search-bar .dropdown-menu a').click(function() {
            var field = $(this).data('field') || '';
            $('#search-field').val(field);
            $('#search-btn').html($(this).text() + ' <span class="caret"></span>');
        });
        $("#keyword").blur(function () {
            getGift(1,5,$(this).val());
        })

        $(document).on("click","#add-pic-btn",function () {
            $('#upload').click();
        })

        $(document).on('input','#upload', function(){
            //alert(11)
            // 创建formdata对象
            var formData = new FormData();
            // 给formData对象添加<input>标签,注意与input标签的ID一致
            formData.append('file', $('#upload')[0].files[0]);
            $.ajax({
                url : '${pageContext.request.contextPath}/LiveController/upload',//这里写你的url
                type : 'POST',
                data : formData,
                contentType: false,// 当有文件要上传时，此项是必须的，否则后台无法识别文件流的起始位置
                processData: false,// 是否序列化data属性，默认true(注意：false时type必须是post)
                dataType: 'json',//这里是返回类型，一般是一般是json,text等
                clearForm: true,//提交后是否清空表单数据
                success: function(result) {   //提交成功后自动执行的处理函数，参数data就是服务器返回的数据。
                    //alert(result);
                    //var result = JSON.parse(data);
                    if (result.img!=null){
                        // alert(data);
                        //$("#add-pic-btn").css("display","none");
                        $("#add-pic-btn").parents("li").html("<figure id = 'figs'>\n" +
                            "                            <img src='${pageContext.request.contextPath}/video/playVideos?videoPath="+result.img+"' alt='"+result.img
                            +"'>\n" +
                            "                            <figcaption id='fig'>\n" +
                            "                              <a class=\"btn btn-round btn-square btn-danger\" href=\"#!\"><i class=\"mdi mdi-delete\"></i></a>\n" +
                            "                            </figcaption>\n" +
                            "                          </figure>");
                    }else{
                        $("#add-pic-btn").html(result.img);
                    }
                }
            })

        });

        $(document).on("click","#fig a",function () {
            $("#figs").parents("li").html("<input type=\"file\" name=\"upload\" id=\"upload1\" style=\"display: none;\" />\n" +
                "<a class=\"pic-add\" id=\"add-pic-btn\" href=\"#!\" title=\"点击上传\"></a>\n");
        })
        //-----------------------------------------------------------------------------------------------------------
        $(document).on("click","#add-pic-btnGif",function () {
            $('#uploadGif').click();
        })

        $(document).on('input','#uploadGif', function(){
            //alert(11)
            // 创建formdata对象
            var formData = new FormData();
            // 给formData对象添加<input>标签,注意与input标签的ID一致
            formData.append('file', $('#uploadGif')[0].files[0]);
            $.ajax({
                url : '${pageContext.request.contextPath}/LiveController/upload',//这里写你的url
                type : 'POST',
                data : formData,
                contentType: false,// 当有文件要上传时，此项是必须的，否则后台无法识别文件流的起始位置
                processData: false,// 是否序列化data属性，默认true(注意：false时type必须是post)
                dataType: 'json',//这里是返回类型，一般是一般是json,text等
                clearForm: true,//提交后是否清空表单数据
                success: function(result) {   //提交成功后自动执行的处理函数，参数data就是服务器返回的数据。
                    //alert(result);
                    //var result = JSON.parse(data);
                    if (result.img!=null){
                        // alert(data);
                        //$("#add-pic-btn").css("display","none");
                        $("#add-pic-btnGif").parents("li").html("<figure id='figs'>\n" +
                            "                            <img src='${pageContext.request.contextPath}/video/playVideos?videoPath="+result.img+"' alt='"+result.img
                            +"'>\n" +
                            "                            <figcaption id='fig' >\n" +
                            "                              <a class=\"btn btn-round btn-square btn-danger\" href=\"#!\"><i class=\"mdi mdi-delete\"></i></a>\n" +
                            "                            </figcaption>\n" +
                            "                          </figure>");
                    }else{
                        $("#add-pic-btnGif").html(result.img);
                    }
                }
            })

        });

        
        $(document).on("click","#fig a",function () {
            $("#figs").parents("li").html("<input type=\"file\" name=\"uploadGif\" id=\"upload\" style=\"display: none;\" />\n" +
                "<a class=\"pic-add\" id=\"add-pic-btnGif\" href=\"#!\" title=\"点击上传\"></a>\n");
        })
        //--------------------------------------------------------------------------------------------------------------------------
        $(document).on("click","#add-pic-btn1",function () {
            $('#upload1').click();
        })

        $(document).on('input','#upload1', function(){
            //alert(11)
            // 创建formdata对象
            var formData = new FormData();
            // 给formData对象添加<input>标签,注意与input标签的ID一致
            formData.append('file', $('#upload1')[0].files[0]);
            $.ajax({
                url : '${pageContext.request.contextPath}/LiveController/upload',//这里写你的url
                type : 'POST',
                data : formData,
                contentType: false,// 当有文件要上传时，此项是必须的，否则后台无法识别文件流的起始位置
                processData: false,// 是否序列化data属性，默认true(注意：false时type必须是post)
                dataType: 'json',//这里是返回类型，一般是一般是json,text等
                clearForm: true,//提交后是否清空表单数据
                success: function(result) {   //提交成功后自动执行的处理函数，参数data就是服务器返回的数据。
                    //alert(result);
                    //var result = JSON.parse(data);
                    if (result.img!=null){
                        // alert(data);
                        //$("#add-pic-btn").css("display","none");
                        $("#add-pic-btn1").parents("li").html("<figure id = 'figs1'>\n" +
                            "                            <img src='${pageContext.request.contextPath}/video/playVideos?videoPath="+result.img+"' alt='"+result.img
                            +"'>\n" +
                            "                            <figcaption id='fig1'>\n" +
                            "                              <a class=\"btn btn-round btn-square btn-danger\" href=\"#!\"><i class=\"mdi mdi-delete\"></i></a>\n" +
                            "                            </figcaption>\n" +
                            "                          </figure>");
                    }else{
                        $("#add-pic-btn1").html(result.img);
                    }
                }
            })

        });

        $(document).on("click","#fig1 a",function () {
            $("#figs1").parents("li").html("<input type=\"file\" name=\"upload1\" id=\"upload1\" style=\"display: none;\" />\n" +
                "<a class=\"pic-add\" id=\"add-pic-btn1\" href=\"#!\" title=\"点击上传\"></a>\n");
        })
        //-----------------------------------------------------------------------------------------------------------
        $(document).on("click","#add-pic-btnGif1",function () {
            $('#uploadGif1').click();
        })

        $(document).on('input','#uploadGif1', function(){
            //alert(11)
            // 创建formdata对象
            var formData = new FormData();
            // 给formData对象添加<input>标签,注意与input标签的ID一致
            formData.append('file', $('#uploadGif1')[0].files[0]);
            $.ajax({
                url : '${pageContext.request.contextPath}/LiveController/upload',//这里写你的url
                type : 'POST',
                data : formData,
                contentType: false,// 当有文件要上传时，此项是必须的，否则后台无法识别文件流的起始位置
                processData: false,// 是否序列化data属性，默认true(注意：false时type必须是post)
                dataType: 'json',//这里是返回类型，一般是一般是json,text等
                clearForm: true,//提交后是否清空表单数据
                success: function(result) {   //提交成功后自动执行的处理函数，参数data就是服务器返回的数据。
                    //alert(result);
                    //var result = JSON.parse(data);
                    if (result.img!=null){
                        // alert(data);
                        //$("#add-pic-btn").css("display","none");
                        $("#add-pic-btnGif1").parents("li").html("<figure id='figsGif1'>\n" +
                            "                            <img src='${pageContext.request.contextPath}/video/playVideos?videoPath="+result.img+"' alt='"+result.img
                            +"'>\n" +
                            "                            <figcaption id='figGif1' >\n" +
                            "                              <a class=\"btn btn-round btn-square btn-danger\" href=\"#!\"><i class=\"mdi mdi-delete\"></i></a>\n" +
                            "                            </figcaption>\n" +
                            "                          </figure>");
                    }else{
                        $("#add-pic-btnGif1").html(result.img);
                    }
                }
            })

        });


        $(document).on("click","#figGif1 a",function () {
            $("#figsGif1").parents("li").html("<input type=\"file\" name=\"uploadGif1\" id=\"uploadGif1\" style=\"display: none;\" />\n" +
                "<a class=\"pic-add\" id=\"add-pic-btnGif1\" href=\"#!\" title=\"点击上传\"></a>\n");
        })
        //--------------------------------------------------------------------------------------------------------------------------
        //add礼物
        $("#add").click(function () {
            var form = new FormData();
            if ($("#giftName").val()!=null&&$("#giftName").val()!=""){
                form.append("giftName",$("#giftName").val());
                if($("#giftPrice").val()!=null&&$("#giftPrice").val()!=""&&isRealNum($("#giftPrice").val())){
                    form.append("giftPrice",$("#giftPrice").val());
                        if ($("figure img").attr("alt")!=""&&$("figure img").attr("alt")!=null){
                            form.append("giftImg",$("figure img").attr("alt"));
                            if ($("#figs img").attr("alt")!=""&&$("#figs img").attr("alt")!=null){
                                form.append("giftGif",$("#figs img").attr("alt"));
                            }else{
                                return alert("图片没有上传!");
                            }
                        }else{
                            return alert("图片没有上传!");
                        }
                    
                }else{
                    return alert("金额不能为空或者不是数据!");
                }
            }else{
                return alert("礼物名不能空!");
            }
            $.ajax({
                url:"${pageContext.request.contextPath}/LiveController/addGift",
                type:"post",
                data:form,
                processData:false,
                contentType:false,
                clearForm: true,//提交后是否清空表单数据
                success:function(data){
                    if (data){
                        alert("添加成功!");
                        $("#giftName").val("")
                        $("#giftPrice").val("")
                        
                        $(".colse").click();
                        getGift($(".pagination .active a").html(),5,"","");
                    }else{
                        alert("添加失败!");
                    }
                }
            });
        })
        $(document).on("click","#updata",function () {
            var form = new FormData();
            form.append("giftId",$("#giftId").val());
            if ($("#giftName1").val()!=null&&$("#giftName1").val()!=""){
                form.append("giftName",$("#giftName1").val());
                if($("#giftPrice1").val()!=null&&$("#giftPrice1").val()!=""&&isRealNum($("#giftPrice1").val())){
                    form.append("giftPrice",$("#giftPrice1").val());
                    if ($("#figs1 img").attr("alt")!=""&&$("#figs1 img").attr("alt")!=null){
                        form.append("giftImg",$("#figs1 img").attr("alt"));
                        if ($("#figsGif1 img").attr("alt")!=""&&$("#figsGif1 img").attr("alt")!=null){
                            form.append("giftGif",$("#figsGif1 img").attr("alt"));
                        }else{
                            return alert("图片没有上传!");
                        }
                    }else{
                        return alert("图片没有上传!");
                    }

                }else{
                    return alert("金额不能为空或者不是数据!");
                }
            }else{
                return alert("礼物名不能空!");
            }
            $.ajax({
                url:"${pageContext.request.contextPath}/LiveController/setGift",
                type:"post",
                data:form,
                processData:false,
                contentType:false,
                clearForm: true,//提交后是否清空表单数据
                success:function(data){
                    if (data){
                        alert("修改成功!");
                        $("#giftName1").val("")
                        $("#giftPrice1").val("")
                        
                        $(".colse").click();
                        getRoom($(".pagination .active a").html(),5,"","");
                    }else{
                        alert("修改失败!");
                    }
                }
            });
        })
        getGift();
        $(document).on("click",".colse",function () {
            $("#figGif1 a").click();
            $("#fig1 a").click();
            $("#figGif a").click();
            $("#fig a").click();
        });

        //登录
        if("${sessionScope.frontUser.userId}"!=""){

            <%--alert("${sessionScope.frontUser}");--%>
            $.get("${pageContext.request.contextPath}/user/checkNameById",{
                userId:"${sessionScope.frontUser.userId}"
            },function (user) {
                var rs="<li class=\"dropdown dropdown-profile\">\n" +
                    "              <a href=\"javascript:void(0)\" data-toggle=\"dropdown\">\n" +
                    "                <img class=\"img-avatar img-avatar-48 m-r-10\" src=\"${pageContext.request.contextPath}/user/frontUserImg?userImg=${sessionScope.frontUser.userImg}\" onerror=\"this.src='${pageContext.request.contextPath}/js/liveJs/98_avatar_middle.jpg'\" alt=\"\" />\n" +
                    "                <span>"+user.userName+" <span class=\"caret\"></span></span>\n" +
                    "              </a>\n" +
                    "              <ul class=\"dropdown-menu dropdown-menu-right\">\n" +
                    "                <li> <a href=\"lyear_pages_profile.html\"><i class=\"mdi mdi-account\"></i> 个人信息</a> </li>\n" +
                    "                <li> <a href=\"lyear_pages_edit_pwd.html\"><i class=\"mdi mdi-lock-outline\"></i> 修改密码</a> </li>\n" +
                    "                <li> <a href=\"javascript:void(0)\"><i class=\"mdi mdi-delete\"></i> 清空缓存</a></li>\n" +
                    "                <li class=\"divider\"></li>\n" +
                    "                <li> <a id=\"exit\" href=\"\"><i class=\"mdi mdi-logout-variant\"></i> 退出登录</a> </li>\n" +
                    "              </ul>\n" +
                    "            </li>";
                $("#login1").html(rs);
                //退出登录
                $(document).on("click","#exit",function () {

                    $.ajax({
                        async:true,
                        type:"GET",
                        url:"${pageContext.request.contextPath}/user/exit",

                        success:function(data){
                            //var content="";
                            window.location.href="${pageContext.request.contextPath}/front/login.jsp";
                            //content = "<a class=\"public-DropMenu-link\" href=\" ${pageContext.request.contextPath}/front/login.jsp\" target=\"_blank\"  style=\"margin-top: 21px;\"><span>登录</span></a>";
                            //填充到指定的标签中
                            //$("#login1").html(content);


                        }
                    });
                });

            });

        }



    });
    var max = 9;
    var min = 1;
    
    function getGift(pageNo,pageSize,giftName) {
        $.getJSON("${pageContext.request.contextPath}/LiveController/getGiftPage",
            {
                giftName:giftName,
                pageNo:pageNo,
                pageSize:pageSize
            }
            ,function (rs) {
                var cont = "";//
                $.each(rs.list,function (index,gift) {
                    cont+="<tr>\n" +
                        "                                            <td>"+gift.giftId+"</td>\n" +
                        "                                            <td>"+gift.giftName+"</td>\n" +
                        "                                            <td>"+gift.giftImg+"</td>\n" +
                        "                                            <td>"+gift.giftGif+"</td>\n" +
                        "                                            <td>"+gift.giftPrice+"</td>\n" +
                        "                                            <td>\n" +
                        "                                                <div class=\"btn-group\">\n" +
                        "                                                    <a class=\"btn btn-xs btn-default\" href=\"#!\" title=\"编辑\" id='updataShow'  data-toggle=\"modal\" data-target=\"#updataModal\" data-gift = \'"+JSON.stringify(gift)+"\' onclick=\"updata("+JSON.stringify(gift)+")\"><i class=\"mdi mdi-pencil\"></i></a>\n" +
                        "                                                    <a class=\"btn btn-xs btn-default\" href=\"#!\" title=\"删除\" data-toggle=\"tooltip\" onclick=\"del('"+gift.giftId+"')\"><i class=\"mdi mdi-window-close\"></i></a>\n" +
                        "                                                </div>\n" +
                        "                                            </td>\n" +
                        "                                        </tr>";
                })
                if (rs.pageNum > max&&rs.pageNum <=rs.pages){
                    min=min+max;
                    max=max+9;
                    if (max > rs.pages){
                        max = rs.pages;
                    }
                    getGiftRecord(rs.pageNum);
                }
                //alert(rs.pageNum < min)
                if (rs.pageNum < min&&rs.pageNum >= 1){
                    max=min-1;
                    min=min-9;
                    getGiftRecord(rs.pageNum);
                }
                var pageCont="";
                if (rs.isFirstPage){
                    pageCont+="<li class=\"disabled\"><span>首页</span></li>"
                }else{
                    pageCont+="<li><a href=\"#!\" onclick='getGift("+1+")'>首页</a></li>"
                }
                if (!rs.hasPreviousPage){
                    pageCont+="<li class=\"disabled\"><span>«</span></li>"
                }else{
                    pageCont+="<li><a href=\"#!\" onclick='getGift("+rs.prePage+")'>«</a></li>"
                }
                for (let i = 1; i <= rs.pages; i++) {
                    if (i==rs.pageNum){
                        pageCont+="<li class=\"active\"><a href=\"#!\" onclick='getGift("+i+")'>"+i+"</a></li>"
                    }else{
                        pageCont+="<li><a href=\"#!\" onclick='getGift("+i+")'>"+i+"</a></li>"
                    }
                }
                if (max < rs.pages){
                    pageCont+="<li ><a href=\"#!\" onclick='getGiftRecord("+(max+1)+")'>...</a></li>"
                }
                if (!rs.hasNextPage){
                    pageCont+="<li class=\"disabled\"><span>»</span></li>"
                }else{
                    pageCont+="<li><a href=\"#!\" onclick='getGift("+rs.nextPage+")'>»</a></li>"
                }
                if (rs.isLastPage){
                    pageCont+="<li class=\"disabled\"><span>末页</span></li>"
                }else{
                    pageCont+="<li><a href=\"#!\" onclick='getGift("+rs.pages+")'>末页</a></li>"
                }
                $(".pagination").html(pageCont);
                $("#tbodyOne").html(cont);
            })
    }

    function del(id) {
        if(confirm("是否确认删除?")){
            $.getJSON("${pageContext.request.contextPath}/LiveController/delGift",{giftId:id},
                function (data) {
                    if (data){
                        alert("删除成功!")
                        getGift()
                    }else{
                        alert("删除失败!")
                        getGift()
                    }
                });
        }
        
    }
    
    $(document).on("click","#updataShow",function () {
        var gift = $(this).data("gift");
        //var room = JSON.parse(json);
        //alert(room);
        $("#giftId").val(gift.giftId);
        $("#giftName1").val(gift.giftName);
        $("#giftPrice1").val(gift.giftPrice);
        $("#add-pic-btn1").parents("li").html("<figure id='figs1'>\n" +
            "                            <img src='${pageContext.request.contextPath}/video/playVideos?videoPath="+gift.giftImg+"' alt='"+gift.giftImg
            +"'>\n" +
            "                            <figcaption id='fig1' >\n" +
            "                              <a class=\"btn btn-round btn-square btn-danger\" href=\"#!\"><i class=\"mdi mdi-delete\"></i></a>\n" +
            "                            </figcaption>\n" +
            "                          </figure>");
        $("#add-pic-btnGif1").parents("li").html("<figure id='figsGif1'>\n" +
            "                            <img src='${pageContext.request.contextPath}/video/playVideos?videoPath="+gift.giftGif+"' alt='"+gift.giftGif
            +"'>\n" +
            "                            <figcaption id='figGif1' >\n" +
            "                              <a class=\"btn btn-round btn-square btn-danger\" href=\"#!\"><i class=\"mdi mdi-delete\"></i></a>\n" +
            "                            </figcaption>\n" +
            "                          </figure>");
    }) 
    
    function isRealNum(val) {
       /* if(typeof val !== 'number'){
            return false;
        }*/
        if(!isNaN(val)){
            return true;
        }else{
            return false;
        }
    }
</script>
</body>
</html>